/*
 * Copyright (c) 2024. The RigelA open source project team and
 * its contributors reserve all rights.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 */

const COLOR_NAMES_MAX: usize = 866;

#[derive(Debug)]
struct ColorInfo {
    name: &'static str,
    rgb: Rgb,
}

#[derive(Debug, Copy, Clone, PartialEq)]
struct Rgb {
    r: u8,
    g: u8,
    b: u8,
}

macro_rules! define {
    ($var:ident,$len:expr,$(($name:literal,$r:expr,$g:expr,$b:expr)),*) => {
        static $var: [ColorInfo; $len] = [
            $(
                ColorInfo { name: $name, rgb: Rgb { r: $r, g: $g, b: $b } }
            ),*
        ];
    };
}

define!(
    COLOR_DATA,
    COLOR_NAMES_MAX,
    ("AirForceBlue(Raf)", 93, 138, 168),
    ("AirForceBlue(Usaf)", 0, 48, 143),
    ("AirSuperiorityBlue", 114, 160, 193),
    ("AlabamaCrimson", 163, 38, 56),
    ("AliceBlue", 240, 248, 255),
    ("AlizarinCrimson", 227, 38, 54),
    ("AlloyOrange", 196, 98, 16),
    ("Almond", 239, 222, 205),
    ("Amaranth", 229, 43, 80),
    ("Amber", 255, 191, 0),
    ("Amber(Sae/Ece)", 255, 126, 0),
    ("AmericanRose", 255, 3, 62),
    ("Amethyst", 153, 102, 204),
    ("AndroidGreen", 164, 198, 57),
    ("Anti-FlashWhite", 242, 243, 244),
    ("AntiqueBrass", 205, 149, 117),
    ("AntiqueFuchsia", 145, 92, 131),
    ("AntiqueRuby", 132, 27, 45),
    ("AntiqueWhite", 250, 235, 215),
    ("Ao(English)", 0, 128, 0),
    ("AppleGreen", 141, 182, 0),
    ("Apricot", 251, 206, 177),
    ("Aqua", 0, 255, 255),
    ("Aquamarine", 127, 255, 212),
    ("ArmyGreen", 75, 83, 32),
    ("Arsenic", 59, 68, 75),
    ("ArylideYellow", 233, 214, 107),
    ("AshGrey", 178, 190, 181),
    ("Asparagus", 135, 169, 107),
    ("AtomicTangerine", 255, 153, 102),
    ("Auburn", 165, 42, 42),
    ("Aureolin", 253, 238, 0),
    ("Aurometalsaurus", 110, 127, 128),
    ("Avocado", 86, 130, 3),
    ("Azure", 0, 127, 255),
    ("AzureMist/Web", 240, 255, 255),
    ("BabyBlue", 137, 207, 240),
    ("BabyBlueEyes", 161, 202, 241),
    ("BabyPink", 244, 194, 194),
    ("BallBlue", 33, 171, 205),
    ("BananaMania", 250, 231, 181),
    ("BananaYellow", 255, 225, 53),
    ("BarnRed", 124, 10, 2),
    ("BattleshipGrey", 132, 132, 130),
    ("Bazaar", 152, 119, 123),
    ("BeauBlue", 188, 212, 230),
    ("Beaver", 159, 129, 112),
    ("Beige", 245, 245, 220),
    ("BigDipO’Ruby", 156, 37, 66),
    ("Bisque", 255, 228, 196),
    ("Bistre", 61, 43, 31),
    ("Bittersweet", 254, 111, 94),
    ("BittersweetShimmer", 191, 79, 81),
    ("Black", 0, 0, 0),
    ("BlackBean", 61, 12, 2),
    ("BlackLeatherJacket", 37, 53, 41),
    ("BlackOlive", 59, 60, 54),
    ("BlanchedAlmond", 255, 235, 205),
    ("Blast-OffBronze", 165, 113, 100),
    ("BleuDeFrance", 49, 140, 231),
    ("BlizzardBlue", 172, 229, 238),
    ("Blond", 250, 240, 190),
    ("Blue", 0, 0, 255),
    ("BlueBell", 162, 162, 208),
    ("Blue(Crayola)", 31, 117, 254),
    ("BlueGray", 102, 153, 204),
    ("Blue-Green", 13, 152, 186),
    ("Blue(Munsell)", 0, 147, 175),
    ("Blue(Ncs)", 0, 135, 189),
    ("Blue(Pigment)", 51, 51, 153),
    ("Blue(Ryb)", 2, 71, 254),
    ("BlueSapphire", 18, 97, 128),
    ("Blue-Violet", 138, 43, 226),
    ("Blush", 222, 93, 131),
    ("Bole", 121, 68, 59),
    ("BondiBlue", 0, 149, 182),
    ("Bone", 227, 218, 201),
    ("BostonUniversityRed", 204, 0, 0),
    ("BottleGreen", 0, 106, 78),
    ("Boysenberry", 135, 50, 96),
    ("BrandeisBlue", 0, 112, 255),
    ("Brass", 181, 166, 66),
    ("BrickRed", 203, 65, 84),
    ("BrightCerulean", 29, 172, 214),
    ("BrightGreen", 102, 255, 0),
    ("BrightLavender", 191, 148, 228),
    ("BrightMaroon", 195, 33, 72),
    ("BrightPink", 255, 0, 127),
    ("BrightTurquoise", 8, 232, 222),
    ("BrightUbe", 209, 159, 232),
    ("BrilliantLavender", 244, 187, 255),
    ("BrilliantRose", 255, 85, 163),
    ("BrinkPink", 251, 96, 127),
    ("BritishRacingGreen", 0, 66, 37),
    ("Bronze", 205, 127, 50),
    ("Brown(Traditional)", 150, 75, 0),
    ("Brown(Web)", 165, 42, 42),
    ("BubbleGum", 255, 193, 204),
    ("Bubbles", 231, 254, 255),
    ("Buff", 240, 220, 130),
    ("BulgarianRose", 72, 6, 7),
    ("Burgundy", 128, 0, 32),
    ("Burlywood", 222, 184, 135),
    ("BurntOrange", 204, 85, 0),
    ("BurntSienna", 233, 116, 81),
    ("BurntUmber", 138, 51, 36),
    ("Byzantine", 189, 51, 164),
    ("Byzantium", 112, 41, 99),
    ("Cadet", 83, 104, 114),
    ("CadetBlue", 95, 158, 160),
    ("CadetGrey", 145, 163, 176),
    ("CadmiumGreen", 0, 107, 60),
    ("CadmiumOrange", 237, 135, 45),
    ("CadmiumRed", 227, 0, 34),
    ("CadmiumYellow", 255, 246, 0),
    ("CaféAuLait", 166, 123, 91),
    ("CaféNoir", 75, 54, 33),
    ("CalPolyGreen", 30, 77, 43),
    ("CambridgeBlue", 163, 193, 173),
    ("Camel", 193, 154, 107),
    ("CameoPink", 239, 187, 204),
    ("CamouflageGreen", 120, 134, 107),
    ("CanaryYellow", 255, 239, 0),
    ("CandyAppleRed", 255, 8, 0),
    ("CandyPink", 228, 113, 122),
    ("Capri", 0, 191, 255),
    ("CaputMortuum", 89, 39, 32),
    ("Cardinal", 196, 30, 58),
    ("CaribbeanGreen", 0, 204, 153),
    ("Carmine", 150, 0, 24),
    ("Carmine(M&P)", 215, 0, 64),
    ("CarminePink", 235, 76, 66),
    ("CarmineRed", 255, 0, 56),
    ("CarnationPink", 255, 166, 201),
    ("Carnelian", 179, 27, 27),
    ("CarolinaBlue", 153, 186, 221),
    ("CarrotOrange", 237, 145, 33),
    ("CatalinaBlue", 6, 42, 120),
    ("Ceil", 146, 161, 207),
    ("Celadon", 172, 225, 175),
    ("CeladonBlue", 0, 123, 167),
    ("CeladonGreen", 47, 132, 124),
    ("Celeste(Colour)", 178, 255, 255),
    ("CelestialBlue", 73, 151, 208),
    ("Cerise", 222, 49, 99),
    ("CerisePink", 236, 59, 131),
    ("Cerulean", 0, 123, 167),
    ("CeruleanBlue", 42, 82, 190),
    ("CeruleanFrost", 109, 155, 195),
    ("CgBlue", 0, 122, 165),
    ("CgRed", 224, 60, 49),
    ("Chamoisee", 160, 120, 90),
    ("Champagne", 250, 214, 165),
    ("Charcoal", 54, 69, 79),
    ("CharmPink", 230, 143, 172),
    ("Chartreuse(Traditional)", 223, 255, 0),
    ("Chartreuse(Web)", 127, 255, 0),
    ("Cherry", 222, 49, 99),
    ("CherryBlossomPink", 255, 183, 197),
    ("Chestnut", 205, 92, 92),
    ("ChinaPink", 222, 111, 161),
    ("ChinaRose", 168, 81, 110),
    ("ChineseRed", 170, 56, 30),
    ("Chocolate(Traditional)", 123, 63, 0),
    ("Chocolate(Web)", 210, 105, 30),
    ("ChromeYellow", 255, 167, 0),
    ("Cinereous", 152, 129, 123),
    ("Cinnabar", 227, 66, 52),
    ("Cinnamon", 210, 105, 30),
    ("Citrine", 228, 208, 10),
    ("ClassicRose", 251, 204, 231),
    ("Cobalt", 0, 71, 171),
    ("CocoaBrown", 210, 105, 30),
    ("Coffee", 111, 78, 55),
    ("ColumbiaBlue", 155, 221, 255),
    ("CongoPink", 248, 131, 121),
    ("CoolBlack", 0, 46, 99),
    ("CoolGrey", 140, 146, 172),
    ("Copper", 184, 115, 51),
    ("Copper(Crayola)", 218, 138, 103),
    ("CopperPenny", 173, 111, 105),
    ("CopperRed", 203, 109, 81),
    ("CopperRose", 153, 102, 102),
    ("Coquelicot", 255, 56, 0),
    ("Coral", 255, 127, 80),
    ("CoralPink", 248, 131, 121),
    ("CoralRed", 255, 64, 64),
    ("Cordovan", 137, 63, 69),
    ("Corn", 251, 236, 93),
    ("CornellRed", 179, 27, 27),
    ("CornflowerBlue", 100, 149, 237),
    ("Cornsilk", 255, 248, 220),
    ("CosmicLatte", 255, 248, 231),
    ("CottonCandy", 255, 188, 217),
    ("Cream", 255, 253, 208),
    ("Crimson", 220, 20, 60),
    ("CrimsonGlory", 190, 0, 50),
    ("Cyan", 0, 255, 255),
    ("Cyan(Process)", 0, 183, 235),
    ("Daffodil", 255, 255, 49),
    ("Dandelion", 240, 225, 48),
    ("DarkBlue", 0, 0, 139),
    ("DarkBrown", 101, 67, 33),
    ("DarkByzantium", 93, 57, 84),
    ("DarkCandyAppleRed", 164, 0, 0),
    ("DarkCerulean", 8, 69, 126),
    ("DarkChestnut", 152, 105, 96),
    ("DarkCoral", 205, 91, 69),
    ("DarkCyan", 0, 139, 139),
    ("DarkElectricBlue", 83, 104, 120),
    ("DarkGoldenrod", 184, 134, 11),
    ("DarkGray", 169, 169, 169),
    ("DarkGreen", 1, 50, 32),
    ("DarkImperialBlue", 0, 65, 106),
    ("DarkJungleGreen", 26, 36, 33),
    ("DarkKhaki", 189, 183, 107),
    ("DarkLava", 72, 60, 50),
    ("DarkLavender", 115, 79, 150),
    ("DarkMagenta", 139, 0, 139),
    ("DarkMidnightBlue", 0, 51, 102),
    ("DarkOliveGreen", 85, 107, 47),
    ("DarkOrange", 255, 140, 0),
    ("DarkOrchid", 153, 50, 204),
    ("DarkPastelBlue", 119, 158, 203),
    ("DarkPastelGreen", 3, 192, 60),
    ("DarkPastelPurple", 150, 111, 214),
    ("DarkPastelRed", 194, 59, 34),
    ("DarkPink", 231, 84, 128),
    ("DarkPowderBlue", 0, 51, 153),
    ("DarkRaspberry", 135, 38, 87),
    ("DarkRed", 139, 0, 0),
    ("DarkSalmon", 233, 150, 122),
    ("DarkScarlet", 86, 3, 25),
    ("DarkSeaGreen", 143, 188, 143),
    ("DarkSienna", 60, 20, 20),
    ("DarkSlateBlue", 72, 61, 139),
    ("DarkSlateGray", 47, 79, 79),
    ("DarkSpringGreen", 23, 114, 69),
    ("DarkTan", 145, 129, 81),
    ("DarkTangerine", 255, 168, 18),
    ("DarkTaupe", 72, 60, 50),
    ("DarkTerraCotta", 204, 78, 92),
    ("DarkTurquoise", 0, 206, 209),
    ("DarkViolet", 148, 0, 211),
    ("DarkYellow", 155, 135, 12),
    ("DartmouthGreen", 0, 112, 60),
    ("Davy'SGrey", 85, 85, 85),
    ("DebianRed", 215, 10, 83),
    ("DeepCarmine", 169, 32, 62),
    ("DeepCarminePink", 239, 48, 56),
    ("DeepCarrotOrange", 233, 105, 44),
    ("DeepCerise", 218, 50, 135),
    ("DeepChampagne", 250, 214, 165),
    ("DeepChestnut", 185, 78, 72),
    ("DeepCoffee", 112, 66, 65),
    ("DeepFuchsia", 193, 84, 193),
    ("DeepJungleGreen", 0, 75, 73),
    ("DeepLilac", 153, 85, 187),
    ("DeepMagenta", 204, 0, 204),
    ("DeepPeach", 255, 203, 164),
    ("DeepPink", 255, 20, 147),
    ("DeepRuby", 132, 63, 91),
    ("DeepSaffron", 255, 153, 51),
    ("DeepSkyBlue", 0, 191, 255),
    ("DeepTuscanRed", 102, 66, 77),
    ("Denim", 21, 96, 189),
    ("Desert", 193, 154, 107),
    ("DesertSand", 237, 201, 175),
    ("DimGray", 105, 105, 105),
    ("DodgerBlue", 30, 144, 255),
    ("DogwoodRose", 215, 24, 104),
    ("DollarBill", 133, 187, 101),
    ("Drab", 150, 113, 23),
    ("DukeBlue", 0, 0, 156),
    ("EarthYellow", 225, 169, 95),
    ("Ebony", 85, 93, 80),
    ("Ecru", 194, 178, 128),
    ("Eggplant", 97, 64, 81),
    ("Eggshell", 240, 234, 214),
    ("EgyptianBlue", 16, 52, 166),
    ("ElectricBlue", 125, 249, 255),
    ("ElectricCrimson", 255, 0, 63),
    ("ElectricCyan", 0, 255, 255),
    ("ElectricGreen", 0, 255, 0),
    ("ElectricIndigo", 111, 0, 255),
    ("ElectricLavender", 244, 187, 255),
    ("ElectricLime", 204, 255, 0),
    ("ElectricPurple", 191, 0, 255),
    ("ElectricUltramarine", 63, 0, 255),
    ("ElectricViolet", 143, 0, 255),
    ("ElectricYellow", 255, 255, 0),
    ("Emerald", 80, 200, 120),
    ("EnglishLavender", 180, 131, 149),
    ("EtonBlue", 150, 200, 162),
    ("Fallow", 193, 154, 107),
    ("FaluRed", 128, 24, 24),
    ("Fandango", 181, 51, 137),
    ("FashionFuchsia", 244, 0, 161),
    ("Fawn", 229, 170, 112),
    ("Feldgrau", 77, 93, 83),
    ("FernGreen", 79, 121, 66),
    ("FerrariRed", 255, 40, 0),
    ("FieldDrab", 108, 84, 30),
    ("FireEngineRed", 206, 32, 41),
    ("Firebrick", 178, 34, 34),
    ("Flame", 226, 88, 34),
    ("FlamingoPink", 252, 142, 172),
    ("Flavescent", 247, 233, 142),
    ("Flax", 238, 220, 130),
    ("FloralWhite", 255, 250, 240),
    ("FluorescentOrange", 255, 191, 0),
    ("FluorescentPink", 255, 20, 147),
    ("FluorescentYellow", 204, 255, 0),
    ("Folly", 255, 0, 79),
    ("ForestGreen(Traditional)", 1, 68, 33),
    ("ForestGreen(Web)", 34, 139, 34),
    ("FrenchBeige", 166, 123, 91),
    ("FrenchBlue", 0, 114, 187),
    ("FrenchLilac", 134, 96, 142),
    ("FrenchLime", 204, 255, 0),
    ("FrenchRaspberry", 199, 44, 72),
    ("FrenchRose", 246, 74, 138),
    ("Fuchsia", 255, 0, 255),
    ("Fuchsia(Crayola)", 193, 84, 193),
    ("FuchsiaPink", 255, 119, 255),
    ("FuchsiaRose", 199, 67, 117),
    ("Fulvous", 228, 132, 0),
    ("FuturamaDeepSpaceBlue", 64, 3, 192),
    ("FuzzyWuzzy", 204, 102, 102),
    ("Gainsboro", 220, 220, 220),
    ("Gamboge", 228, 155, 15),
    ("GhostWhite", 248, 248, 255),
    ("Ginger", 176, 101, 0),
    ("Glaucous", 96, 130, 182),
    ("Glitter", 230, 232, 250),
    ("Gold(Metallic)", 212, 175, 55),
    ("Gold(Web)(Golden)", 255, 215, 0),
    ("GoldenBrown", 153, 101, 21),
    ("GoldenPoppy", 252, 194, 0),
    ("GoldenYellow", 255, 223, 0),
    ("Goldenrod", 218, 165, 32),
    ("GrannySmithApple", 168, 228, 160),
    ("Gray", 128, 128, 128),
    ("Gray-Asparagus", 70, 89, 69),
    ("Gray(Html/CssGray)", 128, 128, 128),
    ("Gray(X11Gray)", 190, 190, 190),
    ("Green(ColorWheel)(X11Green)", 0, 255, 0),
    ("Green(Crayola)", 28, 172, 120),
    ("Green(Html/CssGreen)", 0, 128, 0),
    ("Green(Munsell)", 0, 168, 119),
    ("Green(Ncs)", 0, 159, 107),
    ("Green(Pigment)", 0, 165, 80),
    ("Green(Ryb)", 102, 176, 50),
    ("Green-Yellow", 173, 255, 47),
    ("Grullo", 169, 154, 134),
    ("GuppieGreen", 0, 255, 127),
    ("HalayàúBe", 102, 56, 84),
    ("HanBlue", 68, 108, 207),
    ("HanPurple", 82, 24, 250),
    ("HansaYellow", 233, 214, 107),
    ("Harlequin", 63, 255, 0),
    ("HarvardCrimson", 201, 0, 22),
    ("HarvestGold", 218, 145, 0),
    ("HeartGold", 128, 128, 0),
    ("Heliotrope", 223, 115, 255),
    ("HollywoodCerise", 244, 0, 161),
    ("Honeydew", 240, 255, 240),
    ("HonoluluBlue", 0, 127, 191),
    ("Hooker'SGreen", 73, 121, 107),
    ("HotMagenta", 255, 29, 206),
    ("HotPink", 255, 105, 180),
    ("HunterGreen", 53, 94, 59),
    ("Iceberg", 113, 166, 210),
    ("Icterine", 252, 247, 94),
    ("ImperialBlue", 0, 35, 149),
    ("Inchworm", 178, 236, 93),
    ("IndiaGreen", 19, 136, 8),
    ("IndianRed", 205, 92, 92),
    ("IndianYellow", 227, 168, 87),
    ("Indigo", 111, 0, 255),
    ("Indigo(Dye)", 0, 65, 106),
    ("Indigo(Web)", 75, 0, 130),
    ("InternationalKleinBlue", 0, 47, 167),
    ("InternationalOrange(Aerospace)", 255, 79, 0),
    ("InternationalOrange(Engineering)", 186, 22, 12),
    ("InternationalOrange(GoldenGateBridge)", 192, 54, 44),
    ("Iris", 90, 79, 207),
    ("Isabelline", 244, 240, 236),
    ("IslamicGreen", 0, 144, 0),
    ("Ivory", 255, 255, 240),
    ("Jade", 0, 168, 107),
    ("Jasmine", 248, 222, 126),
    ("Jasper", 215, 59, 62),
    ("JazzberryJam", 165, 11, 94),
    ("Jet", 52, 52, 52),
    ("Jonquil", 250, 218, 94),
    ("JuneBud", 189, 218, 87),
    ("JungleGreen", 41, 171, 135),
    ("KellyGreen", 76, 187, 23),
    ("KenyanCopper", 124, 28, 5),
    ("Khaki(Html/Css)(Khaki)", 195, 176, 145),
    ("Khaki(X11)(LightKhaki)", 240, 230, 140),
    ("KuCrimson", 232, 0, 13),
    ("LaSalleGreen", 8, 120, 48),
    ("LanguidLavender", 214, 202, 221),
    ("LapisLazuli", 38, 97, 156),
    ("LaserLemon", 254, 254, 34),
    ("LaurelGreen", 169, 186, 157),
    ("Lava", 207, 16, 32),
    ("LavenderBlue", 204, 204, 255),
    ("LavenderBlush", 255, 240, 245),
    ("Lavender(Floral)", 181, 126, 220),
    ("LavenderGray", 196, 195, 208),
    ("LavenderIndigo", 148, 87, 235),
    ("LavenderMagenta", 238, 130, 238),
    ("LavenderMist", 230, 230, 250),
    ("LavenderPink", 251, 174, 210),
    ("LavenderPurple", 150, 123, 182),
    ("LavenderRose", 251, 160, 227),
    ("Lavender(Web)", 230, 230, 250),
    ("LawnGreen", 124, 252, 0),
    ("Lemon", 255, 247, 0),
    ("LemonChiffon", 255, 250, 205),
    ("LemonLime", 227, 255, 0),
    ("Licorice", 26, 17, 16),
    ("LightApricot", 253, 213, 177),
    ("LightBlue", 173, 216, 230),
    ("LightBrown", 181, 101, 29),
    ("LightCarminePink", 230, 103, 113),
    ("LightCoral", 240, 128, 128),
    ("LightCornflowerBlue", 147, 204, 234),
    ("LightCrimson", 245, 105, 145),
    ("LightCyan", 224, 255, 255),
    ("LightFuchsiaPink", 249, 132, 239),
    ("LightGoldenrodYellow", 250, 250, 210),
    ("LightGray", 211, 211, 211),
    ("LightGreen", 144, 238, 144),
    ("LightKhaki", 240, 230, 140),
    ("LightPastelPurple", 177, 156, 217),
    ("LightPink", 255, 182, 193),
    ("LightRedOchre", 233, 116, 81),
    ("LightSalmon", 255, 160, 122),
    ("LightSalmonPink", 255, 153, 153),
    ("LightSeaGreen", 32, 178, 170),
    ("LightSkyBlue", 135, 206, 250),
    ("LightSlateGray", 119, 136, 153),
    ("LightTaupe", 179, 139, 109),
    ("LightThulianPink", 230, 143, 172),
    ("LightYellow", 255, 255, 224),
    ("Lilac", 200, 162, 200),
    ("Lime(ColorWheel)", 191, 255, 0),
    ("LimeGreen", 50, 205, 50),
    ("Lime(Web)(X11Green)", 0, 255, 0),
    ("Limerick", 157, 194, 9),
    ("LincolnGreen", 25, 89, 5),
    ("Linen", 250, 240, 230),
    ("Lion", 193, 154, 107),
    ("LittleBoyBlue", 108, 160, 220),
    ("Liver", 83, 75, 79),
    ("Lust", 230, 32, 32),
    ("Magenta", 255, 0, 255),
    ("Magenta(Dye)", 202, 31, 123),
    ("Magenta(Process)", 255, 0, 144),
    ("MagicMint", 170, 240, 209),
    ("Magnolia", 248, 244, 255),
    ("Mahogany", 192, 64, 0),
    ("Maize", 251, 236, 93),
    ("MajorelleBlue", 96, 80, 220),
    ("Malachite", 11, 218, 81),
    ("Manatee", 151, 154, 170),
    ("MangoTango", 255, 130, 67),
    ("Mantis", 116, 195, 101),
    ("MardiGras", 136, 0, 133),
    ("Maroon(Crayola)", 195, 33, 72),
    ("Maroon(Html/Css)", 128, 0, 0),
    ("Maroon(X11)", 176, 48, 96),
    ("Mauve", 224, 176, 255),
    ("MauveTaupe", 145, 95, 109),
    ("Mauvelous", 239, 152, 170),
    ("MayaBlue", 115, 194, 251),
    ("MeatBrown", 229, 183, 59),
    ("MediumAquamarine", 102, 221, 170),
    ("MediumBlue", 0, 0, 205),
    ("MediumCandyAppleRed", 226, 6, 44),
    ("MediumCarmine", 175, 64, 53),
    ("MediumChampagne", 243, 229, 171),
    ("MediumElectricBlue", 3, 80, 150),
    ("MediumJungleGreen", 28, 53, 45),
    ("MediumLavenderMagenta", 221, 160, 221),
    ("MediumOrchid", 186, 85, 211),
    ("MediumPersianBlue", 0, 103, 165),
    ("MediumPurple", 147, 112, 219),
    ("MediumRed-Violet", 187, 51, 133),
    ("MediumRuby", 170, 64, 105),
    ("MediumSeaGreen", 60, 179, 113),
    ("MediumSlateBlue", 123, 104, 238),
    ("MediumSpringBud", 201, 220, 135),
    ("MediumSpringGreen", 0, 250, 154),
    ("MediumTaupe", 103, 76, 71),
    ("MediumTurquoise", 72, 209, 204),
    ("MediumTuscanRed", 121, 68, 59),
    ("MediumVermilion", 217, 96, 59),
    ("MediumViolet-Red", 199, 21, 133),
    ("MellowApricot", 248, 184, 120),
    ("MellowYellow", 248, 222, 126),
    ("Melon", 253, 188, 180),
    ("MidnightBlue", 25, 25, 112),
    ("MidnightGreen(EagleGreen)", 0, 73, 83),
    ("MikadoYellow", 255, 196, 12),
    ("Mint", 62, 180, 137),
    ("MintCream", 245, 255, 250),
    ("MintGreen", 152, 255, 152),
    ("MistyRose", 255, 228, 225),
    ("Moccasin", 250, 235, 215),
    ("ModeBeige", 150, 113, 23),
    ("MoonstoneBlue", 115, 169, 194),
    ("MordantRed19", 174, 12, 0),
    ("MossGreen", 173, 223, 173),
    ("MountainMeadow", 48, 186, 143),
    ("MountbattenPink", 153, 122, 141),
    ("MsuGreen", 24, 69, 59),
    ("Mulberry", 197, 75, 140),
    ("Mustard", 255, 219, 88),
    ("Myrtle", 33, 66, 30),
    ("NadeshikoPink", 246, 173, 198),
    ("NapierGreen", 42, 128, 0),
    ("NaplesYellow", 250, 218, 94),
    ("NavajoWhite", 255, 222, 173),
    ("NavyBlue", 0, 0, 128),
    ("NeonCarrot", 255, 163, 67),
    ("NeonFuchsia", 254, 65, 100),
    ("NeonGreen", 57, 255, 20),
    ("NewYorkPink", 215, 131, 127),
    ("Non-PhotoBlue", 164, 221, 237),
    ("NorthTexasGreen", 5, 144, 51),
    ("OceanBoatBlue", 0, 119, 190),
    ("Ochre", 204, 119, 34),
    ("OfficeGreen", 0, 128, 0),
    ("OldGold", 207, 181, 59),
    ("OldLace", 253, 245, 230),
    ("OldLavender", 121, 104, 120),
    ("OldMauve", 103, 49, 71),
    ("OldRose", 192, 128, 129),
    ("Olive", 128, 128, 0),
    ("OliveDrab#7", 60, 52, 31),
    ("OliveDrab(Web)(OliveDrab#3)", 107, 142, 35),
    ("Olivine", 154, 185, 115),
    ("Onyx", 53, 56, 57),
    ("OperaMauve", 183, 132, 167),
    ("Orange(ColorWheel)", 255, 127, 0),
    ("OrangePeel", 255, 159, 0),
    ("Orange-Red", 255, 69, 0),
    ("Orange(Ryb)", 251, 153, 2),
    ("Orange(WebColor)", 255, 165, 0),
    ("Orchid", 218, 112, 214),
    ("OtterBrown", 101, 67, 33),
    ("OuCrimsonRed", 153, 0, 0),
    ("OuterSpace", 65, 74, 76),
    ("OutrageousOrange", 255, 110, 74),
    ("OxfordBlue", 0, 33, 71),
    ("PakistanGreen", 0, 102, 0),
    ("PalatinateBlue", 39, 59, 226),
    ("PalatinatePurple", 104, 40, 96),
    ("PaleAqua", 188, 212, 230),
    ("PaleBlue", 175, 238, 238),
    ("PaleBrown", 152, 118, 84),
    ("PaleCarmine", 175, 64, 53),
    ("PaleCerulean", 155, 196, 226),
    ("PaleChestnut", 221, 173, 175),
    ("PaleCopper", 218, 138, 103),
    ("PaleCornflowerBlue", 171, 205, 239),
    ("PaleGold", 230, 190, 138),
    ("PaleGoldenrod", 238, 232, 170),
    ("PaleGreen", 152, 251, 152),
    ("PaleLavender", 220, 208, 255),
    ("PaleMagenta", 249, 132, 229),
    ("PalePink", 250, 218, 221),
    ("PalePlum", 221, 160, 221),
    ("PaleRed-Violet", 219, 112, 147),
    ("PaleRobinEggBlue", 150, 222, 209),
    ("PaleSilver", 201, 192, 187),
    ("PaleSpringBud", 236, 235, 189),
    ("PaleTaupe", 188, 152, 126),
    ("PaleViolet-Red", 219, 112, 147),
    ("PansyPurple", 120, 24, 74),
    ("PapayaWhip", 255, 239, 213),
    ("ParisGreen", 80, 200, 120),
    ("PastelBlue", 174, 198, 207),
    ("PastelBrown", 131, 105, 83),
    ("PastelGray", 207, 207, 196),
    ("PastelGreen", 119, 221, 119),
    ("PastelMagenta", 244, 154, 194),
    ("PastelOrange", 255, 179, 71),
    ("PastelPink", 222, 165, 164),
    ("PastelPurple", 179, 158, 181),
    ("PastelRed", 255, 105, 97),
    ("PastelViolet", 203, 153, 201),
    ("PastelYellow", 253, 253, 150),
    ("Patriarch", 128, 0, 128),
    ("Payne'SGrey", 83, 104, 120),
    ("Peach", 255, 229, 180),
    ("Peach(Crayola)", 255, 203, 164),
    ("Peach-Orange", 255, 204, 153),
    ("PeachPuff", 255, 218, 185),
    ("Peach-Yellow", 250, 223, 173),
    ("Pear", 209, 226, 49),
    ("Pearl", 234, 224, 200),
    ("PearlAqua", 136, 216, 192),
    ("PearlyPurple", 183, 104, 162),
    ("Peridot", 230, 226, 0),
    ("Periwinkle", 204, 204, 255),
    ("PersianBlue", 28, 57, 187),
    ("PersianGreen", 0, 166, 147),
    ("PersianIndigo", 50, 18, 122),
    ("PersianOrange", 217, 144, 88),
    ("PersianPink", 247, 127, 190),
    ("PersianPlum", 112, 28, 28),
    ("PersianRed", 204, 51, 51),
    ("PersianRose", 254, 40, 162),
    ("Persimmon", 236, 88, 0),
    ("Peru", 205, 133, 63),
    ("Phlox", 223, 0, 255),
    ("PhthaloBlue", 0, 15, 137),
    ("PhthaloGreen", 18, 53, 36),
    ("PiggyPink", 253, 221, 230),
    ("PineGreen", 1, 121, 111),
    ("Pink", 255, 192, 203),
    ("PinkLace", 255, 221, 244),
    ("Pink-Orange", 255, 153, 102),
    ("PinkPearl", 231, 172, 207),
    ("PinkSherbet", 247, 143, 167),
    ("Pistachio", 147, 197, 114),
    ("Platinum", 229, 228, 226),
    ("Plum(Traditional)", 142, 69, 133),
    ("Plum(Web)", 221, 160, 221),
    ("PortlandOrange", 255, 90, 54),
    ("PowderBlue(Web)", 176, 224, 230),
    ("PrincetonOrange", 255, 143, 0),
    ("Prune", 112, 28, 28),
    ("PrussianBlue", 0, 49, 83),
    ("PsychedelicPurple", 223, 0, 255),
    ("Puce", 204, 136, 153),
    ("Pumpkin", 255, 117, 24),
    ("PurpleHeart", 105, 53, 156),
    ("Purple(Html/Css)", 128, 0, 128),
    ("PurpleMountainMajesty", 150, 120, 182),
    ("Purple(Munsell)", 159, 0, 197),
    ("PurplePizzazz", 254, 78, 218),
    ("PurpleTaupe", 80, 64, 77),
    ("Purple(X11)", 160, 32, 240),
    ("Quartz", 81, 72, 79),
    ("Rackley", 93, 138, 168),
    ("RadicalRed", 255, 53, 94),
    ("Rajah", 251, 171, 96),
    ("Raspberry", 227, 11, 93),
    ("RaspberryGlace", 145, 95, 109),
    ("RaspberryPink", 226, 80, 152),
    ("RaspberryRose", 179, 68, 108),
    ("RawUmber", 130, 102, 68),
    ("RazzleDazzleRose", 255, 51, 204),
    ("Razzmatazz", 227, 37, 107),
    ("Red", 255, 0, 0),
    ("Red-Brown", 165, 42, 42),
    ("RedDevil", 134, 1, 17),
    ("Red(Munsell)", 242, 0, 60),
    ("Red(Ncs)", 196, 2, 51),
    ("Red-Orange", 255, 83, 73),
    ("Red(Pigment)", 237, 28, 36),
    ("Red(Ryb)", 254, 39, 18),
    ("Red-Violet", 199, 21, 133),
    ("Redwood", 171, 78, 82),
    ("Regalia", 82, 45, 128),
    ("ResolutionBlue", 0, 35, 135),
    ("RichBlack", 0, 64, 64),
    ("RichBrilliantLavender", 241, 167, 254),
    ("RichCarmine", 215, 0, 64),
    ("RichElectricBlue", 8, 146, 208),
    ("RichLavender", 167, 107, 207),
    ("RichLilac", 182, 102, 210),
    ("RichMaroon", 176, 48, 96),
    ("RifleGreen", 65, 72, 51),
    ("RobinEggBlue", 0, 204, 204),
    ("Rose", 255, 0, 127),
    ("RoseBonbon", 249, 66, 158),
    ("RoseEbony", 103, 72, 70),
    ("RoseGold", 183, 110, 121),
    ("RoseMadder", 227, 38, 54),
    ("RosePink", 255, 102, 204),
    ("RoseQuartz", 170, 152, 169),
    ("RoseTaupe", 144, 93, 93),
    ("RoseVale", 171, 78, 82),
    ("Rosewood", 101, 0, 11),
    ("RossoCorsa", 212, 0, 0),
    ("RosyBrown", 188, 143, 143),
    ("RoyalAzure", 0, 56, 168),
    ("RoyalBlue(Traditional)", 0, 35, 102),
    ("RoyalBlue(Web)", 65, 105, 225),
    ("RoyalFuchsia", 202, 44, 146),
    ("RoyalPurple", 120, 81, 169),
    ("RoyalYellow", 250, 218, 94),
    ("RubineRed", 209, 0, 86),
    ("Ruby", 224, 17, 95),
    ("RubyRed", 155, 17, 30),
    ("Ruddy", 255, 0, 40),
    ("RuddyBrown", 187, 101, 40),
    ("RuddyPink", 225, 142, 150),
    ("Rufous", 168, 28, 7),
    ("Russet", 128, 70, 27),
    ("Rust", 183, 65, 14),
    ("RustyRed", 218, 44, 67),
    ("SacramentoStateGreen", 0, 86, 63),
    ("SaddleBrown", 139, 69, 19),
    ("SafetyOrange(BlazeOrange)", 255, 103, 0),
    ("Saffron", 244, 196, 48),
    ("Salmon", 255, 140, 105),
    ("SalmonPink", 255, 145, 164),
    ("Sand", 194, 178, 128),
    ("SandDune", 150, 113, 23),
    ("Sandstorm", 236, 213, 64),
    ("SandyBrown", 244, 164, 96),
    ("SandyTaupe", 150, 113, 23),
    ("Sangria", 146, 0, 10),
    ("SapGreen", 80, 125, 42),
    ("Sapphire", 15, 82, 186),
    ("SapphireBlue", 0, 103, 165),
    ("SatinSheenGold", 203, 161, 53),
    ("Scarlet", 255, 36, 0),
    ("Scarlet(Crayola)", 253, 14, 53),
    ("SchoolBusYellow", 255, 216, 0),
    ("Screamin'Green", 118, 255, 122),
    ("SeaBlue", 0, 105, 148),
    ("SeaGreen", 46, 139, 87),
    ("SealBrown", 50, 20, 20),
    ("Seashell", 255, 245, 238),
    ("SelectiveYellow", 255, 186, 0),
    ("Sepia", 112, 66, 20),
    ("Shadow", 138, 121, 93),
    ("ShamrockGreen", 0, 158, 96),
    ("ShockingPink", 252, 15, 192),
    ("ShockingPink(Crayola)", 255, 111, 255),
    ("Sienna", 136, 45, 23),
    ("Silver", 192, 192, 192),
    ("Sinopia", 203, 65, 11),
    ("Skobeloff", 0, 116, 116),
    ("SkyBlue", 135, 206, 235),
    ("SkyMagenta", 207, 113, 175),
    ("SlateBlue", 106, 90, 205),
    ("SlateGray", 112, 128, 144),
    ("Smalt(DarkPowderBlue)", 0, 51, 153),
    ("SmokeyTopaz", 147, 61, 65),
    ("SmokyBlack", 16, 12, 8),
    ("Snow", 255, 250, 250),
    ("SpiroDiscoBall", 15, 192, 252),
    ("SpringBud", 167, 252, 0),
    ("SpringGreen", 0, 255, 127),
    ("St.Patrick'SBlue", 35, 41, 122),
    ("SteelBlue", 70, 130, 180),
    ("StilDeGrainYellow", 250, 218, 94),
    ("Stizza", 153, 0, 0),
    ("Stormcloud", 79, 102, 106),
    ("Straw", 228, 217, 111),
    ("Sunglow", 255, 204, 51),
    ("Sunset", 250, 214, 165),
    ("Tan", 210, 180, 140),
    ("Tangelo", 249, 77, 0),
    ("Tangerine", 242, 133, 0),
    ("TangerineYellow", 255, 204, 0),
    ("TangoPink", 228, 113, 122),
    ("Taupe", 72, 60, 50),
    ("TaupeGray", 139, 133, 137),
    ("TeaGreen", 208, 240, 192),
    ("TeaRose(Orange)", 248, 131, 121),
    ("TeaRose(Rose)", 244, 194, 194),
    ("Teal", 0, 128, 128),
    ("TealBlue", 54, 117, 136),
    ("TealGreen", 0, 130, 127),
    ("Telemagenta", 207, 52, 118),
    ("Tenné(Tawny)", 205, 87, 0),
    ("TerraCotta", 226, 114, 91),
    ("Thistle", 216, 191, 216),
    ("ThulianPink", 222, 111, 161),
    ("TickleMePink", 252, 137, 172),
    ("TiffanyBlue", 10, 186, 181),
    ("Tiger'SEye", 224, 141, 60),
    ("Timberwolf", 219, 215, 210),
    ("TitaniumYellow", 238, 230, 0),
    ("Tomato", 255, 99, 71),
    ("Toolbox", 116, 108, 192),
    ("Topaz", 255, 200, 124),
    ("TractorRed", 253, 14, 53),
    ("TrolleyGrey", 128, 128, 128),
    ("TropicalRainForest", 0, 117, 94),
    ("TrueBlue", 0, 115, 207),
    ("TuftsBlue", 65, 125, 193),
    ("Tumbleweed", 222, 170, 136),
    ("TurkishRose", 181, 114, 129),
    ("Turquoise", 48, 213, 200),
    ("TurquoiseBlue", 0, 255, 239),
    ("TurquoiseGreen", 160, 214, 180),
    ("TuscanRed", 124, 72, 72),
    ("TwilightLavender", 138, 73, 107),
    ("TyrianPurple", 102, 2, 60),
    ("UaBlue", 0, 51, 170),
    ("UaRed", 217, 0, 76),
    ("Ube", 136, 120, 195),
    ("UclaBlue", 83, 104, 149),
    ("UclaGold", 255, 179, 0),
    ("UfoGreen", 60, 208, 112),
    ("UltraPink", 255, 111, 255),
    ("Ultramarine", 18, 10, 143),
    ("UltramarineBlue", 65, 102, 245),
    ("Umber", 99, 81, 71),
    ("UnbleachedSilk", 255, 221, 202),
    ("UnitedNationsBlue", 91, 146, 229),
    ("UniversityOfCaliforniaGold", 183, 135, 39),
    ("UnmellowYellow", 255, 255, 102),
    ("UpForestGreen", 1, 68, 33),
    ("UpMaroon", 123, 17, 19),
    ("UpsdellRed", 174, 32, 41),
    ("Urobilin", 225, 173, 33),
    ("UsafaBlue", 0, 79, 152),
    ("UscCardinal", 153, 0, 0),
    ("UscGold", 255, 204, 0),
    ("UtahCrimson", 211, 0, 63),
    ("Vanilla", 243, 229, 171),
    ("VegasGold", 197, 179, 88),
    ("VenetianRed", 200, 8, 21),
    ("Verdigris", 67, 179, 174),
    ("Vermilion(Cinnabar)", 227, 66, 52),
    ("Vermilion(Plochere)", 217, 96, 59),
    ("Veronica", 160, 32, 240),
    ("Violet", 143, 0, 255),
    ("Violet-Blue", 50, 74, 178),
    ("Violet(ColorWheel)", 127, 0, 255),
    ("Violet(Ryb)", 134, 1, 175),
    ("Violet(Web)", 238, 130, 238),
    ("Viridian", 64, 130, 109),
    ("VividAuburn", 146, 39, 36),
    ("VividBurgundy", 159, 29, 53),
    ("VividCerise", 218, 29, 129),
    ("VividTangerine", 255, 160, 137),
    ("VividViolet", 159, 0, 255),
    ("WarmBlack", 0, 66, 66),
    ("Waterspout", 164, 244, 249),
    ("Wenge", 100, 84, 82),
    ("Wheat", 245, 222, 179),
    ("White", 255, 255, 255),
    ("WhiteSmoke", 245, 245, 245),
    ("WildBlueYonder", 162, 173, 208),
    ("WildStrawberry", 255, 67, 164),
    ("WildWatermelon", 252, 108, 133),
    ("Wine", 114, 47, 55),
    ("WineDregs", 103, 49, 71),
    ("Wisteria", 201, 160, 220),
    ("WoodBrown", 193, 154, 107),
    ("Xanadu", 115, 134, 120),
    ("YaleBlue", 15, 77, 146),
    ("Yellow", 255, 255, 0),
    ("Yellow-Green", 154, 205, 50),
    ("Yellow(Munsell)", 239, 204, 0),
    ("Yellow(Ncs)", 255, 211, 0),
    ("YellowOrange", 255, 174, 66),
    ("Yellow(Process)", 255, 239, 0),
    ("Yellow(Ryb)", 254, 254, 51),
    ("Zaffre", 0, 20, 168),
    ("ZinnwalditeBrown", 44, 22, 8)
);

/**
 * 根据RGB颜色获取最接近的颜色名称。
 * `r` 红色分量。
 * `g` 绿色分量。
 * `b` 蓝色分量。
 * */
pub fn get_nearest_color_name(r: u8, g: u8, b: u8) -> &'static str {
    let rr = r as f64 / 255.0;
    let gg = g as f64 / 255.0;
    let bb = b as f64 / 255.0;

    let mut best_index = 0;
    let mut min_error = f64::INFINITY;

    for (i, ref color) in COLOR_DATA.iter().enumerate() {
        let rd = color.rgb.r as f64 / 255.0;
        let gd = color.rgb.g as f64 / 255.0;
        let bd = color.rgb.b as f64 / 255.0;

        let error = (rd - rr).powi(2) + (gd - gg).powi(2) + (bd - bb).powi(2);
        let error = error.sqrt();

        if error < min_error {
            min_error = error;
            best_index = i;
        }
    }
    COLOR_DATA[best_index].name
}

#[cfg(test)]
mod test_color {
    use crate::color::get_nearest_color_name;

    #[test]
    fn main() {
        assert_eq!(get_nearest_color_name(0, 0, 0), "Black");
        assert_eq!(get_nearest_color_name(255, 255, 255), "White");
        assert_eq!(get_nearest_color_name(255, 0, 0), "Red");
        assert_eq!(get_nearest_color_name(0, 255, 0), "ElectricGreen");
        assert_eq!(get_nearest_color_name(0, 0, 255), "Blue");
        assert_eq!(get_nearest_color_name(50, 80, 40), "RifleGreen");
    }
}
